package com.joker.airoleplayplatformback.domain.enums;

import lombok.Getter;

@Getter
public enum AppHttpCodeEnum {
    // 成功
    SUCCESS(200, "操作成功"),
    //服务器内部异常
    INTERNAL_SERVER_ERROR(505, "未知的服务器内部异常"),
    //参数不合法
    PARAMS_ERROR(401, "请求参数不合法"),

    USER_FRIEND_EXIST(402, "对不起，已经是好友了，不能进行申请"),

    USER_APPLY_EXIST(405, "申请已经存在，不能重复进行时申请"),
    //无权限
    NO_AUTH(403, "没有执行操作的权限"),
    //请求的资源不存在
    NOT_EXIST(404, "请求的资源不存在"),
    // 登录
    CODE_EXCEPTION(10001, "验证码获取频率太高，请稍后再试"),
    WRONG_CODE(10002, "验证码错误"),
    ACCOUNT_NOT_EXIST(10003, "账号不存在"),
    WRONG_PASSWORD(10004, "密码错误"),
    THIRD_PARTY_EXCEPTION(10005, "第三方登录异常"),
    NOT_LOGIN(10006, "未登录"),
    //注册
    PHONE_EXIST(10011, "手机号已注册"),
    EMAIL_EXIST(10012, "邮箱已注册"),
    USER_EXIST(10013, "用户已存在"),
    //用户属性
    USER_TAG_EXIST(10021, "该标签已存在"),
    USERNAME_EXIST(10022, "用户名已存在"),
    //文章标签
    ARTICLE_TAG_EXIST(11031, "该标签已存在"),

    SYSTEM_ERROR(-1, "系统出小差了，请稍后再试哦~~"),
    PARAM_VALID(-2, "参数校验失败{0}"),
    FREQUENCY_LIMIT(-3, "请求太频繁了，请稍后再试哦~~"),
    LOCK_LIMIT(-4, "请求太频繁了，请稍后再试哦~~"),

    //OJ相关
    SUBMIT_ERROR(20001, "提交判题失败"),
    //代码沙箱
    DANGER_CODE(21001, "危险代码"),

    NOT_FRIEND(21004, "二者不是好友"),

    MESSAGE_NOT_SEND(21003, "消息发送失败"),

    ROOM_NOT_EXIST(21002, "房间id不存在");


    public int code;
    public String msg;

    AppHttpCodeEnum(int code, String errorMessage) {
        this.code = code;
        this.msg = errorMessage;
    }

    public static AppHttpCodeEnum getEnumByCode(int code) {
        for (AppHttpCodeEnum appHttpCodeEnum : AppHttpCodeEnum.values()) {
            if (appHttpCodeEnum.code == code) {
                return appHttpCodeEnum;
            }
        }
        return AppHttpCodeEnum.INTERNAL_SERVER_ERROR;
    }
}
